import arcpy, csv
from arcpy import env
env.overwriteOutput='TRUE'


def main():
    list=[10,11]
    global period, island_num, csv_name, years
    period= "totalRate.gdb"
    csv_name="r"
    years=140
    
    
    for i in list:
        island_num=str(i)
        print "Working...."
        print
        print
        print
        print i
        print
        print
        mainy(i)
    
def mainy(num):


    fc="E:\\cp\\newShores\\"+period+"\\Trans"+str(island_num)+"UTM"
    fp="E:\\cp\\newShores\\"+period+"\\Intersect"+str(island_num)
    
    fields=["SHAPE@","OBJECTID","TransOrder"]
    scursor=arcpy.da.SearchCursor(fc,fields)
    pcursor=arcpy.da.SearchCursor(fp,fields)

    

    glist=[]
    for i in scursor:
        
        geom=i[0]
        reg=findIt(i[2])
        
        if reg== None:
            print "No Match for", i[2]
            continue
        for p in pcursor:
            if p[2]==i[2]:
                intp=p[0]
                break
            intp=0
        pcursor.reset()
        if intp != 0:
            startdist= intp.distanceTo(geom.firstPoint)
            if reg != -1:
                pos=move(reg,geom,startdist)
                glist.append(pos)
    
    
    arcpy.CopyFeatures_management(glist, "E:\\cp\\newShores\\"+period+"\\newShore"+str(island_num)+"_"+str(2010+years))



def findIt(tid):
    
    with open("E:\\cp\\csv\\"+str(csv_name+island_num)+".csv",'rb') as csvf:
        cread = csv.reader(csvf)
    
        for i in cread:
            
            if str(i[1])== str(tid):
               
                num=i[8]
                if num=="-1.#IND":
                    num=0                
                return float(num)
def move(reg,geom,start):
        length=geom.length
        dist = start+(reg*years)
        pos=geom.positionAlongLine(dist)
        return pos

    
    
main()  
